package com.adjt.droidsapiens;

import activity_semestres.NovoSemestre;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import database.DatabaseConnector;

public class Home extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				DatabaseConnector db = new DatabaseConnector(getBaseContext());
				String[] colunas = { "idSemestre" };
				Cursor c;
				db.open();
				c = db.buscar("Semestre", colunas, "", "");
				db.close();

				final Intent it;
				if (c.getCount() == 0) {
					it = new Intent(getBaseContext(), NovoSemestre.class);
					it.putExtra("firstRun", true);
				} else {
					it = new Intent(getBaseContext(), MainHome.class);
				}
				startActivity(it);
				finish();
			}
		}, 3000);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}
}
